package com.ruoyi.smartcity.huanjing.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.smartcity.huanjing.domain.HuanjingShuizhi;
import com.ruoyi.smartcity.huanjing.service.IHuanjingShuizhiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 水质Controller
 * 
 * @author ruoyi
 * @date 2025-03-06
 */
@RestController
@RequestMapping("/smartcity/huanjing/shuizhi")
public class HuanjingShuizhiController extends BaseController
{
    @Autowired
    private IHuanjingShuizhiService huanjingShuizhiService;

    /**
     * 查询水质列表
     */
    @GetMapping("/list")
    public TableDataInfo list(HuanjingShuizhi huanjingShuizhi)
    {
        startPage();
        List<HuanjingShuizhi> list = huanjingShuizhiService.selectHuanjingShuizhiList(huanjingShuizhi);
        return getDataTable(list);
    }

    /**
     * 导出水质列表
     */
    @Log(title = "水质", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HuanjingShuizhi huanjingShuizhi)
    {
        List<HuanjingShuizhi> list = huanjingShuizhiService.selectHuanjingShuizhiList(huanjingShuizhi);
        ExcelUtil<HuanjingShuizhi> util = new ExcelUtil<HuanjingShuizhi>(HuanjingShuizhi.class);
        util.exportExcel(response, list, "水质数据");
    }

    /**
     * 获取水质详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(huanjingShuizhiService.selectHuanjingShuizhiById(id));
    }

    /**
     * 新增水质
     */
    @Log(title = "水质", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HuanjingShuizhi huanjingShuizhi)
    {
        return toAjax(huanjingShuizhiService.insertHuanjingShuizhi(huanjingShuizhi));
    }

    /**
     * 修改水质
     */
    @Log(title = "水质", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HuanjingShuizhi huanjingShuizhi)
    {
        return toAjax(huanjingShuizhiService.updateHuanjingShuizhi(huanjingShuizhi));
    }

    /**
     * 删除水质
     */
    @Log(title = "水质", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(huanjingShuizhiService.deleteHuanjingShuizhiByIds(ids));
    }
}
